﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfCharRain
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        Random WhichMovingRandom = new Random();
        private delegate void outputDelegate(string msg);
        public  DispatcherTimer dtGlobal = new DispatcherTimer();
        public int GetMovingNumber()
        {
            return MyStatck.Children.Cast<CharRainLineControl>().Where(m=>m.IsMoving).Count();
        }
        public MainWindow()
        {
            InitializeComponent();
        }

        void dt_Tick(object sender, EventArgs e)
        {//为了节省资源，所有事情都放在这里
            ///处理字符下落事件
            ///

            ////////////////////
            tbDateTime.Text = DateTime.Now.ToString();
        }

        private void InitMe()
        {
            for (int i = 0; i < Config.ScreenWidth / Config.Font_Size; i++)
            {
                CharRainLineControl ccr = new CharRainLineControl(this,MyStatck, WhichMovingRandom);
            }
            dtGlobal.Interval = new TimeSpan(0, 0, 0, 0, 15);
            dtGlobal.Tick += dt_Tick;
            dtGlobal.Start();
        }
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyboardDevice.IsKeyDown(Key.Escape))
            {
                this.ExitFullscreen();
                this.Close();
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.GoFullscreen();
            InitMe();
        }

    }
}
